package com.biubiushop.controller;

import cn.hutool.core.util.StrUtil;
import com.biubiushop.service.IEquipmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.sql.rowset.serial.SerialException;
import java.io.Serializable;
import java.util.List;

/**
 * @author chenjia
 * @date 2019/06/25
 */
@RestController
@RequestMapping("/shareTissue")
@Api(tags = "设备模块")
public class EquipmentController {

    @Resource
    IEquipmentService equipmentService;

    @ApiOperation(value = "添加设备")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "设备类型", required = true),
            @ApiImplicitParam(name = "agentId", value = "设备所属代理人id", required = true),
            @ApiImplicitParam(name = "longitude", value = "设备坐标经度", required = true),
            @ApiImplicitParam(name = "latitude", value = "设备坐标纬度", required = true),
            @ApiImplicitParam(name = "address", value = "设备详细地址", required = true),
            @ApiImplicitParam(name = "overLength", value = "剩余纸巾总长度", required = true),
            @ApiImplicitParam(name = "isUse", value = "是否启用(0-已使用(true),1-未使用(false))", required = false),
            @ApiImplicitParam(name = "isNormal", value = "设备是否正常(0-正常(true),1-异常(false))", required = false)

    })
    @PostMapping("/equipment/v1/addEquipment")
    public Serializable addEquipment(Integer type, String agentId, Double longitude, Double
            latitude, String address, Boolean isUse, Boolean isNormal, Integer overLength) throws Exception {
        if (StrUtil.hasEmpty(agentId)) {
            throw new SerialException("参数为空");
        }
        Boolean succeed = equipmentService.addEquipment(type, agentId, longitude, latitude, address, isUse, isNormal, overLength);
        return succeed;
    }

    @GetMapping("/equipment/v1/getNearEquipment")
    public Serializable getNearEquipment(Double longitude, Double latitude) throws Exception {
        if (longitude == null || latitude == null) {
            throw new SerialException("参数为空");
        }
        List<Object> list = equipmentService.getNearEquipment(longitude, latitude);
        return (Serializable) list;
    }

}
